package sng.net.http
{
	/**
	 * 
	 * Http发送进程容器 
	 * @author leonliu
	 * 
	 */	
	public class ThreadsPool
	{
		/**
		 * 设置发送线程池的线程数据
		 */		
		private const CACHE_NUM:uint = 3;
		
		/**
		 * 
		 */		
		private var _threadHolder:Vector.<SendThread>;
		
		
		public function ThreadsPool()
		{
			_threadHolder = new Vector.<SendThread>(CACHE_NUM, true);
			
			initCache();
			
		}
		
		private function initCache():void
		{
			for(var i:uint = 0; i < CACHE_NUM; ++i)
			{
				_threadHolder[i] = new SendThread();
			}
		}
		
		
		/**
		 * 获取可用的Thread 
		 * @return 
		 * 
		 */		
		public function getThread():SendThread
		{
			for(var i:uint = 0; i < CACHE_NUM; ++i)
			{
				var thread:SendThread = _threadHolder[i];
				
				if(thread && thread.usable)
				{
					return thread;
				}
			}
			
			return null;
		}
		
	}
}